package com.server.llh.llhserverwork.activity.my;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TextView;

import com.llh.llhsuppliers.R;
import com.server.llh.llhserverwork.activity.work.HealthFinishActivity;
import com.server.llh.llhserverwork.activity.work.HealthTaskActivity;
import com.server.llh.llhserverwork.activity.work.HelpActivity;
import com.server.llh.llhserverwork.bean.Constants;
import com.server.llh.llhserverwork.utils.SharedPreferenceUtil;


public  class MyTaskActivity extends TabActivity implements
        OnCheckedChangeListener, OnClickListener {
    private TabHost mHost;
    private RadioGroup main_radio;
    RadioButton radio_finish, radio_unfinish, radio_three,tabbar_four;
    private Intent finish, unfinish, three,four;
    private ImageButton image_back;
    private TextView textName, serverName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setFullScreen(false);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_health_tab);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        initView();
    }
    String signStatus,signCustomerId;
    public void initView() {
        textName = (TextView) findViewById(R.id.titleName);
        textName.setText("我的任务");
        serverName = (TextView) findViewById(R.id.serverName);
        serverName.setVisibility(View.VISIBLE);
        serverName.setBackgroundResource(R.drawable.back_style);
        signStatus = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.SIGN_STATUS,
                getApplicationContext());
        signCustomerId = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.SIGN_CUSTOMER_ID,
                getApplicationContext());
        if ("1".equals(signStatus)) {
            serverName.setText("已签到");
        } else {
            serverName.setText("已签退");
        }
        serverName.setOnClickListener(this);
        main_radio = (RadioGroup) findViewById(R.id.main_radio);
        main_radio.setOnCheckedChangeListener(this);

        image_back = (ImageButton) findViewById(R.id.main_back);
        image_back.setOnClickListener(this);

        this.finish = new Intent(this, HealthTaskActivity.class);
        this.finish.putExtra("tastType", "");
        this.finish.putExtra("transStatus", "4,5");
        this.unfinish = new Intent(this, HealthFinishActivity.class);
        this.unfinish.putExtra("tastType", "");
        this.unfinish.putExtra("transStatus", "6");
        this.three = new Intent(this, HealthFinishActivity.class);
        this.three.putExtra("tastType", "");
        this.three.putExtra("transStatus", "9");
        this.four = new Intent(this, HelpActivity.class);
        initRadios();
        setupIntent();
        radio_finish.setChecked(true);
    }

    private void initRadios() {
        radio_finish = (RadioButton) findViewById(R.id.tabbar_one);
        radio_unfinish = (RadioButton) findViewById(R.id.tabbar_two);
        radio_three = (RadioButton) findViewById(R.id.tabbar_three);
        tabbar_four = (RadioButton) findViewById(R.id.tabbar_four);
    }

    /**
     * 切换模块
     */
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        if (checkedId == R.id.tabbar_one) {
            this.mHost.setCurrentTabByTag("finish");
        } else if (checkedId == R.id.tabbar_two) {
            this.mHost.setCurrentTabByTag("unfinish");
        } else if (checkedId == R.id.tabbar_three) {
            this.mHost.setCurrentTabByTag("three");
        }else if(checkedId==R.id.tabbar_four){
            this.mHost.setCurrentTabByTag("four");
        }
    }
    private void setupIntent() {
        this.mHost = getTabHost();
        TabHost localTabHost = this.mHost;
        localTabHost.addTab(buildTabSpec("finish", "待执行", this.finish));
        localTabHost.addTab(buildTabSpec("unfinish", "已执行", this.unfinish));
        localTabHost.addTab(buildTabSpec("three", "已拒绝", this.three));
        localTabHost.addTab(buildTabSpec("four", "紧急", this.four));
    }

    private TabHost.TabSpec buildTabSpec(String tag, String resLabel,
                                         final Intent content) {
        return this.mHost.newTabSpec(tag).setIndicator(resLabel)
                .setContent(content);
    }

    public void setFullScreen(boolean fullScreen) {
        if (fullScreen) {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        } else {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
        }
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.serverName) {
            Intent intent = new Intent(getApplicationContext(),
                    SignInActivity.class);
            startActivity(intent);
            finish();
        } else {
            onBackPressed();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        signStatus = SharedPreferenceUtil.getUserInfo(Constants.UserInfo.SIGN_STATUS,getApplicationContext());
        if ("1".equals(signStatus)) {
            serverName.setText("签退");
        } else {
            serverName.setText("签到");
        }
    }
}
